home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 April: Mac OS SDK / Dev.CD Apr 98 SDK2.toast / Development Kits (Disc 2) / ScriptX / Documentation / Code Examples from Docs / compguid / printing / textprn / scrllprs.sx < prev    next >
Encoding:
Text File  |  1996-05-21  |  4.1 KB  |  136 lines  |  [TEXT/ttxt]

  1. --<<<-
  2. -- Filename:
  3. --      scrllprs.sx
  4.  
  5. -- Other files required
  6. --        textprin.sx
  7.  
  8. -- Purpose:
  9. --         Defines classes that are used in the test for printing text.
  10.  
  11. --======================================================================================
  12. -- ScrollingTextPresenter
  13. --        Creates a ScrollingPresenter with only the vertical scrollbar and which
  14. --        uses a TextPresenter (or TextEdit) as its targetPresenter. 
  15. --
  16. -- Parameters:
  17. --        same as ScrollingPresenter        
  18. --
  19. -- Usage: 
  20. --        new ScrollingTextPresenter targetPresenter:[TextPresenter]
  21. --
  22. -- Main classes used:
  23. --        ScrollingPresenter
  24. --        ScrollBar
  25. --======================================================================================
  26. class ScrollingTextPresenter (ScrollingPresenter)
  27. end
  28.  
  29. method init self {class ScrollingTextPresenter} #rest args -> (
  30.  
  31.     apply nextmethod self fill:whitebrush stroke:(new Brush color:redcolor) args
  32.     local aRect := new Rect x2:16 y2:16
  33.     -- Create presenters for the different parts of the scrollbar
  34.     local redRect := new TwoDShape boundary:(new rect x2:16 y2:16) fill:(new Brush color: redColor) stroke: blackBrush
  35.     local blueRect := new TwoDShape boundary:(new rect x2:16 y2:16) fill:(new Brush color: blueColor) stroke: blackBrush
  36.     local greenRect := new TwoDShape boundary:(new rect x2:16 y2:16) fill:(new Brush color: greenColor) stroke: blackBrush
  37.     local yellowRect := new TwoDShape boundary:(new rect x2:16 y2:16) fill:(new Brush color: yellowColor) stroke: blackBrush
  38.     
  39.     -- Create a vertical scrollbar
  40.     local theScrollbar := new scrollBar orientation:@vertical
  41.     theScrollbar.thumbStencil := aRect
  42.     theScrollbar.decrementStencil := aRect
  43.     theScrollbar.incrementStencil := aRect
  44.     theScrollbar.stepAmount := 5
  45.     theScrollbar.pageAmount := 20
  46.     theScrollbar.directDrag := true
  47.     
  48.     self.vertScrollbar := theScrollbar
  49.     
  50.     return self
  51. )
  52.  
  53.  
  54. --======================================================================================
  55. -- TextWindow
  56. --        Creates an Window which contains a scrolling text field and 3 buttons. Defines
  57. --        a printWindow method for the Window subclass that prints the text edit.
  58. --
  59. -- Parameters:
  60. --        same as Window
  61. --
  62. -- Usage: 
  63. --        new TextWindow 
  64. --
  65. -- Main classes used:
  66. --        Window
  67. --        ScrollingTextPresenter
  68. --        CutCopyPasteButtons
  69. --======================================================================================
  70. class TextWindow (Window)
  71. instance variables
  72.     textEd
  73.     scrpres
  74. end
  75.  
  76. method init self {class TextWindow} #rest args -> (
  77.     apply nextmethod self boundary:(new rect x2:560 y2:320) \
  78.                           name:"Scrollable/Editable Text" \
  79.                           fill:blackBrush centered:true args
  80.  
  81.     -- Import plain text file 
  82.     local theStream := getStream theScriptDir "text.rtf" @readable
  83.     local theText := importMedia theImportExportEngine theStream @text @rtf @richtext
  84.     
  85.     -- Create a presenter to display the text
  86.     self.textEd := new TextEdit boundary:(new rect x2:540 y2:1024) target:theText 
  87.     self.textEd.cursor := new rect x1:0 y1:-12 x2:2 y2:4        --create an visible insertion point for the text
  88.     self.textEd.cursorbrush := new brush color:blackcolor
  89.     self.textEd.selectionforeground := new brush color:redColor
  90.     self.textEd.selectionbackground := new brush color:yellowColor
  91.     
  92.     -- Add text to a scrolling text field
  93.     self.scrpres := (new ScrollingTextPresenter targetPresenter:self.textEd)
  94.     self.scrpres.width := 560; self.scrpres.height := 320
  95.     
  96.     -- Add scrolling text field to window
  97.     append self self.scrpres
  98.  
  99.     -- Define the actuator controller to control the pushbuttons
  100.     local actControl := new actuatorController space:self
  101.     actControl.wholespace := true
  102.     
  103.     return self
  104. )
  105.  
  106. method printWindow self {class TextWindow} -> (
  107.     threadCriticalUp()
  108.     self.compositor.enabled := false
  109.     
  110.     self.scrpres.targetPresenter := undefined
  111.     
  112.     printText self.textEd #(1, 1, 1, 1) @inches
  113.     
  114.     self.scrpres.targetPresenter := self.textEd
  115.     
  116.     self.compositor.enabled := true
  117.     threadCriticalDown() 
  118. )
  119.  
  120. method cut self {class TextWindow} -> (
  121.     cut self.textEd
  122. )
  123.  
  124. method copy self {class TextWindow} -> (
  125.     copy self.textEd
  126. )
  127.  
  128. method paste self {class TextWindow} -> (
  129.     paste self.textEd
  130. )
  131.  
  132. global win := new TextWindow
  133. show win
  134. -->>>
  135.  
  136.